<template>
	<view class="" style="width: 100%;">
		<view class="shop_box">
			<view class="shop_msg" @click="handLook()">
				<image class="icon" :src="item[newProps.imgUrl]" mode="aspectFill">
				</image>
				<view class="msg">
					<view class="title_box">
						<view class="title">
							<view class="name">
								{{item[newProps.name]}}
							</view>
							<u-tag v-if="item.isAutarky==1" text="自营店" mode='dark' bg-color="#FFA147" size='mini'
								class="" />
						</view>
						<slot name='right-btn'>
							<view class="go">
								看店
								<u-icon color="#646464" name="arrow-right"></u-icon>
							</view>
						</slot>

					</view>
					<view class="msg_bottom">
						<view class="num_box">
							<view class="num">
								已卖出：{{item.salesVolume}}+件
							</view>
							<u-rate size='mini' active-color='#FF365D' :current="item.score" :disabled="true"></u-rate>
							<view class="distance" v-if="showDistance">
								<u-icon color="#ff365d" name="map"></u-icon> 距离{{distance}}km
							</view>
						</view>
						<view class="goods_num" v-if="showGoodsNum">
							商品数量：{{item.goodsCount}}
						</view>
					</view>
				</view>
			</view>
			<scroll-view scroll-x="true" v-if="showGoods" class="goods_info_list">
				<!-- <view class="goods_info_list"> -->
				<view @click="handGoodsNavTo(goods)" class="goods_item" v-for="(goods,index) in item.goodsInfoListVos"
					:key='index'>
					<u-image style="width: 100%;height: 100%;" class="goods_img" :src="goods.imgUrl" mode="aspectFill">
					</u-image>
					<u-tag bg-color='#8E8E8E' size='mini' class="tag" :text="'¥'+goods.price" mode="dark" />
				</view>
				<!-- </view> -->
			</scroll-view>

		</view>
		<u-gap v-if="showgap" height="14" bg-color="#ECECEC"></u-gap>
	</view>
</template>

<script>
	import {
		getMapDistance
	} from '@/utils/utils.js'
	export default {
		name: "ZY-shop",
		computed: {
			distance() {
				const longitude = this.cache.getCache('longitude')
				const latitude = this.cache.getCache('latitude')
				if (latitude && longitude) {
					return (getMapDistance(latitude, longitude, this.item.lat, this.item.lng)).toFixed(2)
				}
			},
			newProps() {
				let props = {
					name: 'name',
					imgUrl: 'imgUrl',
				}
				return {
					...props,
					...this.props
				}
			}
		},
		props: {
			/* 配置项 */
			props: {
				type: Object,
				default: () => {
					return {
						name: 'name',
						imgUrl: 'imgUrl'
					}
				}
			},
			item: {
				type: Object,
				default: () => {}
			},
			showGoods: {
				type: Boolean,
				default: true
			},
			showDistance: {
				type: Boolean,
				default: true
			},
			showgap: {
				type: Boolean,
				default: true
			},
			showGoodsNum: {
				type: Boolean,
				default: false
			},
		},
		data() {
			return {

			};
		},
		methods: {
			handGoodsNavTo(item) {
				uni.navigateTo({
					url: '/pages/followShop/goodsDetail/goodsDetail?id=' + item.id,
				})
			},
			handLook() {
				this.$emit('handLook')
			},
			// handNavToShopDetail(){

			// }
		}
	}
</script>

<style lang="scss" scoped>
	.distance {
		color: $u-type-primary;
		margin-left: 10rpx;
	}


	.goods_info_list {
		margin-top: 30rpx;
		// display: flex;
		// flex-wrap: nowrap;
		white-space: nowrap;
		// width: 750rpx;
		width: 100%;
		// overflow: auto;

	}

	.goods_item {
		display: inline-block;
		width: 160rpx;
		height: 160rpx;
		position: relative;
		margin-right: 20rpx;

		&:last-child {
			margin-right: 0;
		}

		.tag {
			position: absolute;
			bottom: 22rpx;
			left: 50%;
			transform: translate(-50%, 0);
		}

		.goods_img {
			width: 100%;
			height: 100%;
		}
	}

	.shop_box {
		padding: 30rpx;
		width: 100%;

		.msg_bottom {
			display: flex;
			justify-content: space-between;

			.goods_num {
				font-size: 22rpx;
				color: #A4A4A4;
			}
		}

		.num_box {
			display: flex;
			align-items: center;

			margin-right: 10rpx;

			.num {
				font-size: 22rpx;
				color: #B9B9B9;
			}
		}

		.shop_msg {
			display: flex;


			// justify-content: space-between;
			.icon {
				width: 83rpx;
				height: 83rpx;
				min-width: 83rpx;
				margin-right: 25rpx;
			}

			.msg {
				display: flex;
				flex-direction: column;
				justify-content: space-between;
				width: 100%;
				height: 83rpx;

				.title_box {
					display: flex;
					justify-content: space-between;
					align-items: center;
					width: 100%;

					.go {
						color: #646464;
						font-size: 24rpx;
					}

					.title {
						display: flex;
						align-items: center;

						.name {
							margin-right: 10rpx;
							color: #101010;
							font-size: 34rpx;
							font-weight: 600;
						}
					}
				}
			}
		}
	}
</style>
